'''
BM14 链表的奇偶重排
'''

class ListNode:
    def __init__(self,val,next=None):
        self.val = val
        self.next = next


class Solution:
    def oddEvenList(self , head: ListNode) -> ListNode:
        if head == None:
            return head
        odd = head
        even = head.next
        evenList = even
        while even and even.next:
            odd.next = even.next
            odd = odd.next
            even.next = odd.next
            even = even.next

        odd.next = evenList
        return head

def printList(node: ListNode):
    while node:
        print(node.val, end="->" if node.next else "\n")
        node = node.next

if __name__ == "__main__":
    node = ListNode(1, ListNode(2, ListNode(3, ListNode(4, ListNode(5)))))
    listnode = Solution().oddEvenList(node)
    printList(listnode)